extends IEventBehavior


class_name HitRedirect
"""
朝不同方向射击,子弹运行一段距离后向上射击
"""


## 发射子弹的重定向设置
@export var settings: Array[PackedStateResource] = []


func support() -> Array:
    return [0, CharacterUnit.Event.ON_HIT_EXECUTE]

static func spawn(source: ProjectileResource, state: PackedStateResource, weapon: GunWeapon, factory: INodeFactory) -> Projectile:
    var b: Projectile = weapon.spawn(source, factory)
    if state and state.elements.size() > 0:
        var move: MoveComponent = b.element.subassembly("Move")
        var m: MoveController = MoveController.new()
        m.state = state
        m.is_release_state_when_completed = true
        NodeHelper.add_child(move, m)
        move.append(m)
    return b

## 处理子弹初始化事件
func do_event(character: CharacterComponent, v: EffectValue, e: CharacterEvent) -> void:
    var source: ProjectileResource = e.meta.source
    var projectile: Projectile = e.meta.projectile
    for state in settings:
        var b: Projectile = spawn(source, state, projectile.weapon, null)
        b.processor = projectile.processor.clone()
    e.cancel()
